package com.ruoyi.web.controller.comprehensive;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.comprehensive.dto.VentilationDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comprehensive.domain.VentilationPrevention;
import com.ruoyi.comprehensive.service.IVentilationPreventionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通风管理Controller
 * 
 * @author hcc
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/comprehensive/prevention")
public class VentilationPreventionController extends BaseController
{
    @Autowired
    private IVentilationPreventionService ventilationPreventionService;

    /**
     * 查询通风管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:prevention:list')")
    @GetMapping("/list")
    public TableDataInfo list(VentilationPrevention ventilationPrevention)
    {
        startPage();
        List<VentilationPrevention> list = ventilationPreventionService.selectVentilationPreventionList(ventilationPrevention);
        return getDataTable(list);
    }

    /**
     * 导出通风管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:prevention:export')")
    @Log(title = "通风管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VentilationPrevention ventilationPrevention)
    {
        List<VentilationPrevention> list = ventilationPreventionService.selectVentilationPreventionList(ventilationPrevention);
        ExcelUtil<VentilationPrevention> util = new ExcelUtil<VentilationPrevention>(VentilationPrevention.class);
        util.exportExcel(response, list, "通风管理数据");
    }

    /**
     * 获取通风管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:prevention:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ventilationPreventionService.selectVentilationPreventionById(id));
    }

    /**
     * 新增通风管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:prevention:add')")
    @Log(title = "通风管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VentilationPrevention ventilationPrevention)
    {
        ventilationPrevention.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(ventilationPreventionService.insertVentilationPrevention(ventilationPrevention));
    }

    /**
     * 修改通风管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:prevention:edit')")
    @Log(title = "通风管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult edit(@RequestBody VentilationPrevention ventilationPrevention)
    {
        return toAjax(ventilationPreventionService.updateVentilationPrevention(ventilationPrevention));
    }

    /**
     * 删除通风管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:prevention:remove')")
    @Log(title = "通风管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ventilationPreventionService.deleteVentilationPreventionByIds(ids));
    }

    /**
     * 查询通风管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:prevention:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(VentilationPrevention ventilationPrevention)
    {
        startPage();
        List<VentilationDto> list = ventilationPreventionService.getVentilationPreventionList(ventilationPrevention);
        return getDataTable(list);
    }
}
